package com.xhd.base.session;


import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Map;

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
import com.xhd.base.util.Date;
import com.xhd.server.ServerConfig;
import com.xhd.server.XServerId;

public class Session
implements Serializable
{
private static final long jm51 = 1L;
static final String jm100 = "times";
static final String jm101 = "cpcsessionid";
static final String jm102 = "serverid";
static final String jm103 = "userbean";
static final String jm104 = "clientinfo";
static final String jm105 = "vaultbean";
static final String jm106 = "checkmsgtime";
static final String jm107 = "loginguid";
static final String jm108 = "timestamp";
public static final String KEY_MSG_SERVER = "msgserverid";
public static final String KEY_OLD_ID = "oldsessionid";
public static final String KEY_ONLINE = "isonline";
final String jm109 = "groupid";
private Hashtable jm110 = new Hashtable();

public Session()
{
  setSessionData(null);
}

public Session(Map paramMap)
{
  setSessionData(paramMap);
}

public void flashAction()
{
  setAttribute("times", new Date());
  setAttribute("serverid", ServerConfig.ServerId);
}

public void flashAction(long paramLong)
{
  Date localDate = new Date();
  localDate.setTime(paramLong);
  setAttribute("times", localDate);
}

public void flashCheckMsg(long paramLong)
{
  if (paramLong <= getCheckMsgTime())
    return;
  Date localDate = new Date();
  localDate.setTime(paramLong);
  setAttribute("checkmsgtime", localDate);
}

public long getActionTime()
{
  Date localDate = (Date)getAttribute("times");
  if (localDate != null)
    return localDate.getTime();
  return 0L;
}

public Object getAttribute(String paramString)
{
  if (this.jm110 != null)
    return this.jm110.get(paramString);
  return null;
}

public long getCheckMsgTime()
{
  Date localDate = (Date)getAttribute("checkmsgtime");
  return ((localDate != null) ? localDate.getTime() : 0L);
}

public SessionClientInfo getClientInfo()
{
  return ((SessionClientInfo)getAttribute("clientinfo"));
}

public String getGUID()
{
  return ((String)getAttribute("loginguid"));
}

public String getId()
{
  return ((String)getAttribute("cpcsessionid"));
}

public String getServerId()
{
  return ((String)getAttribute("serverid"));
}

public Hashtable getSessionData()
{
  return this.jm110;
}

public SessionUserInfo getUserInfo()
{
  return ((SessionUserInfo)getAttribute("userbean"));
}

public SessionVaultInfo getVaultInfo()
{
  return ((SessionVaultInfo)getAttribute("vaultbean"));
}

public boolean isLocal()
{
  String str = getServerId();
  if ((str == null) || (str.length() < 1))
    return true;
  return str.equals(ServerConfig.ServerId);
}

public boolean isOnline()
{
  String str = (String)getAttribute("isonline");
  return ((str != null) && ("2".equals(str)));
}

public void setOnline(boolean paramBoolean)
{
  setAttribute("isonline", (paramBoolean) ? "2" : "1");
  if (!(paramBoolean))
    return;
  setAttribute("msgserverid", XServerId.getLocal().getId());
}

public void setOnline(String paramString)
{
  setAttribute("isonline", "2");
  setAttribute("msgserverid", paramString);
}

public boolean isValid()
{
  String str = getId();
  if ((str == null) || (str.length() < 1))
    return false;
  if (!(this.jm110.containsKey("times")))
    return false;
  if (!(this.jm110.containsKey("userbean")))
    return false;
  if (!(this.jm110.containsKey("vaultbean")))
    return false;
  if (!(this.jm110.containsKey("clientinfo")))
    return false;
  long l1 = System.currentTimeMillis();
  long l2 = ((Date)this.jm110.get("times")).getTime();
  return ((l1 - l2) / 60000L <= ServerConfig.SessionMinutes);
}

public boolean loadFromFile(File paramFile)
{
  if ((paramFile != null) && (paramFile.exists()) && (paramFile.isFile()))
  {
    FileInputStream localFileInputStream = null;
    ObjectInputStream localObjectInputStream = null;
    try
    {
      localFileInputStream = new FileInputStream(paramFile);
      localObjectInputStream = new ObjectInputStream(localFileInputStream);
      int i = localObjectInputStream.readInt();
      int j = localObjectInputStream.readInt();
      for (int k = 0; k < j; ++k)
      {
        String str = localObjectInputStream.readUTF();
        Object localObject = localObjectInputStream.readObject();
        if ((str == null) || (localObject == null))
          continue;
        setAttribute(str, localObject);
      }
     int  k = localObjectInputStream.readInt();
      localObjectInputStream.close();
      localFileInputStream.close();
      if (i == k)
        return true;
    }
    catch (Exception localException1)
    {
      try
      {
        if (localObjectInputStream != null)
          localObjectInputStream.close();
        if (localFileInputStream != null)
          localFileInputStream.close();
      }
      catch (Exception localException2)
      {
      }
    }
  }
  return false;
}

public void setAttribute(String paramString, Object paramObject)
{
  if ((this.jm110 == null) || (paramObject == null))
    return;
  this.jm110.put(paramString, paramObject);
}

public void setClientInfo(SessionClientInfo paramSessionClientInfo)
{
  if (paramSessionClientInfo == null)
    return;
  setAttribute("clientinfo", paramSessionClientInfo);
}

public void setGUID(String paramString)
{
  if (this.jm110 == null)
    return;
  setAttribute("loginguid", paramString);
}

public void setSessionData(Map paramMap)
{
  this.jm110 = new Hashtable();
  if (paramMap == null)
    return  ;
  ((Map) this.jm110).putAll(paramMap);
}

public void setUserInfo(SessionUserInfo paramSessionUserInfo)
{
  if (paramSessionUserInfo == null)
    return;
  setAttribute("userbean", paramSessionUserInfo);
}

public void setVaultInfo(SessionVaultInfo paramSessionVaultInfo)
{
  if (paramSessionVaultInfo == null)
    return;
  setAttribute("vaultbean", paramSessionVaultInfo);
}

public long lastFlashTime()
{
  long l1 = getActionTime();
  long l2 = getCheckMsgTime();
  return ((l1 > l2) ? l1 : l2);
}

protected void setId(String paramString)
{
  setAttribute("cpcsessionid", paramString);
}

public boolean store()
{
  if ((ServerConfig.AlwaysSaveSession) && (isValid()))
    return SessionManager.getInstance().getStore().save(this);
  return false;
}

public String getMsgServer()
{
  return ((String)getAttribute("msgserverid"));
}

public void invalid()
{
  if (this.jm110 == null)
    return;
  Object localObject = this.jm110.get("cpcsessionid");
  if (localObject == null)
    return;
  this.jm110.put("oldsessionid", localObject);
  this.jm110.remove("cpcsessionid");
}

public int getGroupId()
{
  String str = (String)getAttribute("groupid");
  if ((str == null) || (str.length() < 1))
    return 0;
  return Integer.parseInt(str);
}

protected void setGroupId(int paramInt)
{
  setAttribute("groupid", String.valueOf(paramInt));
}

public long getTimestamp()
{
  String str = (String)getAttribute("timestamp");
  if ((str == null) || (str.length() < 1))
    return 0L;
  return Long.parseLong(str);
}

public void setTimestamp(long paramLong)
{
  setAttribute("timestamp", String.valueOf(paramLong));
}
}
